package Day16_13;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    //贪心
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n * 3];
        for(int i = 0; i < n * 3; i++){
            arr[i] = in.nextInt();
        }
        long ans = 0;
        Arrays.sort(arr);
        int i = n;
        int index = n * 3 - 1 - 1;
        while(i > 0){
           ans +=  arr[index];
           index -= 2;
           i--;
        }
        System.out.println(ans);
    }

    //dp
    public int deleteAndEarn(int[] nums) {
        int[] arr = new int[10001];
        int[] dp = new int[10001];
        int maxV = -1;
        for(int e : nums){
            maxV = Math.max(maxV, e);
            arr[e]++;
        }
        dp[1] = arr[1];
        dp[2] = arr[2] * 2;
        for(int i = 2; i <= maxV; i++){
            dp[i] = Math.max(dp[i - 2] + arr[i] * i, dp[i - 1]);
        }
        return dp[maxV];
    }
}
